import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {
  Form,
  Input
} from 'antd';


export default class UpdateForm extends Component {

  myRef = React.createRef()

  static propTypes = {
    categoryName: PropTypes.string.isRequired,
    setForm: PropTypes.func.isRequired
  }

  // UNSAFE_componentWillMount () {
  //   this.props.setForm(this.myRef.current.value || '')
  // }
  componentDidMount () {
    console.log(this.myRef.current);
    this.props.setForm(this.myRef.current)
  }
  render () {
    const { categoryName } = this.props
    return (
      <Form
        ref={this.myRef}
      >
        <Form.Item
          label="分类名称"
          name="categoryName"
          initialValue={categoryName}
          rules={[
            {
              required: true,
              message: '请输入分类名称!',
            },
          ]}
        >
          <Input placeholder="请输入分类名称" />
        </Form.Item>
      </Form>
    )
  }
}
